package com.blockchain.console.servlets.user;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.XlbEntity;
import com.blockchain.console.service.user.UserManage;
import com.blockchain.console.service.user.entity.ZhxxEntity;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.query.PagingResult;
import com.blockchain.util.parser.IntegerParser;

public class FinanceEdit extends AbstractUserServlet {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		
		UserManage usermanager = serviceSession.getService(UserManage.class);
		String userid = request.getParameter("userid");
	    ZhxxEntity rmbZhxx = usermanager.rmbZhxx(IntegerParser.parse(userid));
	    
	    request.setAttribute("rmb", rmbZhxx);
	    request.setAttribute("userid", userid);
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		PagingResult<XlbEntity> xlbs = tsradingManage.xlbSearch();
		request.setAttribute("coinList", xlbs);
		forwardView(request, response, getClass());
	}
	
	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		if (serviceSession.getSession().getAccountId() != 1) {
			return;
		}
		PrintWriter out = response.getWriter();
		Map<String,Object> result  = new HashMap<>();
		result.put("num", "0");
		result.put("msg", "");

		UserManage usermanager = serviceSession.getService(UserManage.class);
		String userid = request.getParameter("userid");
		int bid = IntegerParser.parse(request.getParameter("bid"));
	    if (bid > 0) {
	    	ZhxxEntity xlbZhxx = usermanager.xlbZhxx(IntegerParser.parse(userid), bid);
		
			if (xlbZhxx!=null) {
				out.write(xlbZhxx.ky.toString());
				return;
			}
	    }
	}
	
}
